<?php
/**
 * User: WL
 * Time: 12-10-13 - 上午9:14
 * File: list.inc.php
 * Project For ixdcw.com
 */
/**
 * 2013-4-1 Sameal add order by cityid an group level
 */
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE.'/'.$module.'/common.inc.php';
require_once DT_INC.'/post.func.php';
//检测模块和列表是否符合，
ViewCheck::catExists() or Prompt::listNotFound();
ViewCheck::groupListPermission() or Prompt::noPermission();
//引用公共头部模版
require DT_CORE.'/buyhelp/common.inc.php';
$navname='quote';
//$maincat = Search::mainCat(MODULE_NAME, $catid);
$condition = "status=3";
// normal
$filter['catid']  = getgpc('catid');
$filter['areaid'] = getgpc('areaid');
$filter['typeid'] = getgpc('typeid');

// auto
$filter['ctp'] = getgpc('ctp');
//$filter['bid'] = getgpc('bid');
$filter['cid'] = getgpc('cid');
$filter['cen'] = getgpc('cen');
// if do not match
//右上和下面的筛选配合使用
$matchCtp = $filter['ctp'] && in_array($cartypeid, array(1,2,3)) && matchCTP($filter['ctp'], $cartypeid);
$matchCen = $filter['cen'] && $cartypeid == 4 && $filter['cen'] != 432;
//满足条件时,根据cookie传入的$cartypeid给 $filter赋值
if (!$matchCen && !$matchCtp) {
    if ($cartypeid == 1) {
        $filter['ctp'] = 433;
        $imgtypeid = 433;
    }
    if ($cartypeid == 2) {
        $filter['ctp'] = 434;
        $imgtypeid = 434;
    }
    if ($cartypeid == 3) {
        $filter['ctp'] = 435;
        $imgtypeid = 435;
    }
    if ($cartypeid == 4) {
        $filter['cen'] = 432;
        $filter['ctp']='';
        $imgtypeid = 432;
    }
}
// 地区搜索.
//if($cityid) {
//	$condition .=  " AND (city like '%|".$cityid."|%' or city like '%|0|%') ";
//}
////搜索
if ($kw) {
    $condition .= " AND title LIKE '%$kw%'";
}
if (!empty($CAT)) {
    $condition .= ($CAT['child']) ? " AND catid IN (" . $CAT['arrchildid'] . ")" : " AND catid=$catid ";
}
require_once DT_INC . '/search/listAuto.inc.php';
$BRANDS_S =  $BRANDS ? $BRANDS : '';
if ($autoFilter) {
    $carids   = $carids ? $carids : array('-');
    $brandids = $brandids ? $brandids : array('-');

    $condition .= " and arcid in (" . Sql::in($carids) . ")";
   // $condition .= " and arbid in (" . Sql::in($brandids) . ")";
}
//先去找缓存文件。
$total    = $db->count($table, $condition, $DT['cache_search']);
$do = new QuoteModule($moduleid);
//图片信息集合
$levels = PCache::read('autoCategory-level.php');
$imglist_condition = "select * from {$db->getPre()}information ";
$imglist_condition.=" where cartypeid=".$cartypeid;
$imglist_condition.=" and status=3 ";
$imglist_condition.=" and thumb!='' ";
$imglist_condition.=" order by edittime desc limit 6";
if ($total) {
    //按照时间排序最新的 && 地区排序
	if ($cityid) {
		$orders = "(case when (city like '%|".$cityid."|%' or city like '%|0|%') then 1 else 2 end ),edittime DESC";
	}else{
		$orders = 'edittime DESC';
	}
	//将整个行情里面的信息取出
    $pagesize=8;
    //需要的字段。
    $fields='title,itemid,addtime,edittime';
    $tags=$do->getList($condition,$orders,($DT['cache_search'] && $page == 1) ? 'CACHE' : '',8,$fields);
    //图片信息
    $imglist=$db->getAll($imglist_condition);
    //针对性的取出行情了里面的信息：优惠，和预订
    //优惠的信息集合
    $youhui_condition = $condition ;
    $youhui_condition.=' and catid=3600 ';
    $discount=$do->getList($youhui_condition,$orders,($DT['cache_search']) ? 'CACHE' : '',$pagesize,$fields);
    //到店预订的信息集合
    $yuding_condition = $condition;
    $yuding_condition.=' and catid=3599 ';
    $orderByshop=$do->getList($yuding_condition,$orders,($DT['cache_search']) ? 'CACHE' : '',$pagesize,$fields);
    //预约试驾的信息集合。
    $tableG= Table::name(Table::NAME_GUIDE);
    /*车型类别 车系id*/
    $autoId = AutoCategoryModule::getCarbylevel($cartypeid);
    $sql = "select itemid,title,thumb,linkurl,edittime from $tableG where  arcid in($autoId) and status=3 order by edittime desc limit 8";
    $guide_shijia = $db->getAll($sql);
    //车贷
    $load_condition="select title,itemid,edittime from {$db->getPre()}information where status=3 and catid=5153 order by {$orders} limit 8";

    $load_data=$db->getAll($load_condition);
    if($page == 1 && $kw) keyword($kw, $items, $moduleid);
}

$seo_file = 'list';
include DT_INC.'/seo.inc.php';
include template('index', $module);